package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.OrderProduct;
import com.ktgj.customer.service.IOrderProductService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 订单附加产品Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/product")
public class TravelOrderProductController extends BaseController
{
    @Autowired
    private IOrderProductService orderProductService;

    /**
     * 查询订单附加产品列表
     */
    @PreAuthorize(hasPermi = "customer:product:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderProduct orderProduct)
    {
        startPage();
        List<OrderProduct> list = orderProductService.selectOrderProductList(orderProduct);
        return getDataTable(list);
    }

    /**
     * 导出订单附加产品列表
     */
    @PreAuthorize(hasPermi = "customer:product:export")
    @Log(title = "订单附加产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderProduct orderProduct) throws IOException
    {
        List<OrderProduct> list = orderProductService.selectOrderProductList(orderProduct);
        ExcelUtil<OrderProduct> util = new ExcelUtil<OrderProduct>(OrderProduct.class);
        util.exportExcel(response, list, "订单附加产品数据");
    }

    /**
     * 获取订单附加产品详细信息
     */
    @PreAuthorize(hasPermi = "customer:product:query")
    @GetMapping(value = "/{orderProductId}")
    public AjaxResult getInfo(@PathVariable("orderProductId") Long orderProductId)
    {
        return AjaxResult.success(orderProductService.selectOrderProductById(orderProductId));
    }

    /**
     * 新增订单附加产品
     */
    @PreAuthorize(hasPermi = "customer:product:add")
    @Log(title = "订单附加产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderProduct orderProduct)
    {
        return toAjax(orderProductService.insertOrderProduct(orderProduct));
    }

    /**
     * 修改订单附加产品
     */
    @PreAuthorize(hasPermi = "customer:product:edit")
    @Log(title = "订单附加产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderProduct orderProduct)
    {
        return toAjax(orderProductService.updateOrderProduct(orderProduct));
    }

    /**
     * 删除订单附加产品
     */
    @PreAuthorize(hasPermi = "customer:product:remove")
    @Log(title = "订单附加产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderProductIds}")
    public AjaxResult remove(@PathVariable Long[] orderProductIds)
    {
        return toAjax(orderProductService.deleteOrderProductByIds(orderProductIds));
    }
}
